﻿using LibNiconico.NiconicoApi.Extentions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace LibNiconico.NiconicoApi.Alert
{
    /// <summary>
    /// アラートステータス
    /// </summary>
    public class NicoAlertStatus
    {
        /// <summary>
        /// ユーザID
        /// </summary>
        public string UserId
        {
            get;
            private set;
        }

        /// <summary>
        /// ユーザハッシュコード
        /// </summary>
        public string UserHash
        {
            get;
            private set;
        }

        /// <summary>
        /// メッセージサーバ
        /// </summary>
        public NicoAlertMessageServer MessageServer
        {
            get;
            private set;
        }


        internal NicoAlertStatus()
        {
            this.UserId = "";
            this.UserHash = "";
            this.MessageServer = new NicoAlertMessageServer();
        }


        internal static NicoAlertStatus Parse(XDocument document)
        {
            var status = new NicoAlertStatus();
            NicoAlertStatus.Parse(status, document);
            return status;
        }

        internal static void Parse(NicoAlertStatus instance, XDocument document)
        {
            var element = document.Element("getalertstatus");
            if (element != null)
            {
                instance.UserId = XElementExtention.GetElementAsString(element, "user_id");
                instance.UserHash = XElementExtention.GetElementAsString(element, "user_hash");
                instance.MessageServer = NicoAlertMessageServer.Parse(element.Element("ms"));
            }
            

        }
    }
}
